package com.yanwq.sayhi.service;

import com.yanwq.sayhi.bean.Article;
import com.yanwq.sayhi.bean.Comment;
import com.yanwq.sayhi.repository.CommentRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 作者：yanweiqiang。
 * 日期：2016/2/24。
 */
@Service
public class CommentService {

    @Autowired
    private CommentRepo repository;

    public Comment save(Comment comment) {
        return repository.save(comment);
    }

    public List<Comment> listByArticle(Article article, int page, int size) {
        Page<Comment> comments = repository.findByArticleOrderByPublishTimeDesc(article, new PageRequest(page, size));
        return comments.getContent();
    }
}
